#include <mutex>
#include <map>
#include <memory>
#include "data.h"

namespace eintik::data::scan {
    std::map<int, std::shared_ptr<AScan>> g_ascan;
    std::mutex g_mutex_ascan;

    std::map<int, std::shared_ptr<SScan>> g_sscan;
    std::mutex g_mutex_sscan;

    std::map<int, std::shared_ptr<CScan>> g_cscan;
    std::mutex g_mutex_cscan;

    std::map<int, std::shared_ptr<DScan>> g_dscan;
    std::mutex g_mutex_dscan;

    AScan *ascan(int id)
    {
        std::lock_guard<std::mutex> lock(g_mutex_ascan);
        if (g_ascan.find(id) == g_ascan.end()) {
            g_ascan[id] = std::make_shared<AScan>();
        }
        return g_ascan[id].get();
    }
    SScan *sscan(int id)
    {
        std::lock_guard<std::mutex> lock(g_mutex_sscan);
        if (g_sscan.find(id) == g_sscan.end()) {
            g_sscan[id] = std::make_shared<SScan>();
        }
        return g_sscan[id].get();
    }
    CScan *cscan(int id)
    {
        std::lock_guard<std::mutex> lock(g_mutex_cscan);
        if (g_cscan.find(id) == g_cscan.end()) {
            g_cscan[id] = std::make_shared<CScan>();
        }
        return g_cscan[id].get();
    }
    DScan *dscan(int id)
    {
        std::lock_guard<std::mutex> lock(g_mutex_dscan);
        if (g_dscan.find(id) == g_dscan.end()) {
            g_dscan[id] = std::make_shared<DScan>();
        }
        return g_dscan[id].get();
    }

}
